import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 三石
 * Date: 2022-08-08
 * Time: 16:53
 */

public class test1 {

    /**
     *
     */
    //字典序排序
    static boolean dictionary(String[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            for (int k = 0; k < arr[i].length(); k++) {
                if (arr[i].charAt(k)<arr[i+1].charAt(k)){
                    return true;
                }else if (arr[i].charAt(k)>arr[i+1].charAt(k)){
                    return false;
                }

            }
        }
        return true;
    }
    //长度排序
    static boolean Length(String[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            for (int k = 0; k < arr[i].length(); k++) {
                if (arr[i].length()<=arr[i+1].length()){
                    return true;
                }else if (arr[i].charAt(k)>arr[i+1].charAt(k)){
                    return false;
                }

            }
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] arr = new String[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextLine();
        }
        boolean ret1= Length(arr);
        boolean ret2=dictionary(arr);
        if (ret1==false && ret2==true){
            System.out.println("dictionary");
        }else if (ret1==true && ret2==false){
            System.out.println("Length");
        }else if(ret1==true && ret2==true){
            System.out.println("both");
        }else {
            System.out.println("none");
        }
    }



    public int MoreThanHalfNum_Solution (int[] numbers) {
        // write code here
        //[1,2,3,2,2,2,5,4,2]
        Scanner in = new Scanner(System.in);
        String arr=in.nextLine();
        int len=arr.length();

        for (int i = 1; i < len; i++) {
            char ch=arr.charAt(i);
            char tmp=arr.charAt(0);
            if(ch==tmp){

            }else {

            }
        }
        return -1;
    }

    public static void main22(String[] args) {
        //abcd12345ed125ss123456789
        Scanner in = new Scanner(System.in);
        String str=in.nextLine();
        String p1="";
        String p2="";
        for (int i = 0; i < str.length(); i++) {
            char n=str.charAt(i);
            if(n>= '0'&&n<= '9'){ //只要是数字就会进来
                p1=p1+n;  //空字符串和数字拼接，把数字变成字符串储存
            }else { //说明此时的前面的连续数字已经断了，需要比较哪一个字符串（数字）的长度，
                   // 把长的数字组永远赋给p2,
                if(p1.length()>p2.length()){
                    p2=p1;
                }
                p1="";//然后p1清空，继续接收连续数字
            }
        }
        if(p1.length()>p2.length()){
          p2=p1;
        }
        System.out.println(p2);
    }
    public static void main21(String[] args) {
        Scanner in = new Scanner(System.in);
        String string=in.nextLine();
        String[] arr=string.split(" ");
        for (int i=arr.length-1;i>=0;i--){
            System.out.print(arr[i]+" ");
        }

    }
    public static void main20(String[] args) {
        Scanner in1 = new Scanner(System.in);
        int n = in1.nextInt();
        int[] arr = new int[n+1];
        int i = 0;
        int count = 0;
        for ( i = 0; i < n; i++) {
            arr[i] = in1.nextInt();
        }
        i=0;
                while (i<n){
                    if (arr[i] < arr[i + 1]) {
                        while (i<n&&arr[i] < arr[i + 1]){
                            i++;
                        }
                        count++;
                        i++;
                    } else if(arr[i] == arr[i + 1]){
                        while (i<n&&arr[i] == arr[i + 1]){
                            i++;
                        }
                    }else {
                        while (i<n-1){
                            while (i<n&&arr[i] > arr[i + 1]){
                                i++;
                            }
                            count++;
                            i++;
                        }

                    }
                }
            System.out.println(count);
        }


    public static void main19(String[] args) {

            Scanner in = new Scanner(System.in);
            //String arr1="They are students";
            String arr1= in.nextLine();
            String arr2= in.nextLine();
        // String arr2="aeiou";
           char[]  ch=arr1.toCharArray();
           int i=0;
        for ( i = 0; i < ch.length; i++) {
            if (!arr2.contains(String.valueOf(ch[i]))){
                System.out.print(ch[i]);
            }
         }
    }

    public static void main17(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int j=1,i=0,y=0;
        int[] arr1=new int[3*n];
        while(j<=3*n){
                arr1[i]=in.nextInt();
                i++;
                j++;
        }
        for (i=0;i<3*n;i+=3){
            Arrays.sort(arr1,i,i+3);
        }

        int sum=0;
        for (i=1;i<3*n;i+=3){
            sum+=arr1[i];
        }
        System.out.println(sum);
    }
    public static void main36(String[] args) {
        MyBinaryTree myBinaryTree=new MyBinaryTree();
        MyBinaryTree.TreeNode root=myBinaryTree.createTree();
        System.out.println("前序遍历");
        myBinaryTree.preOrder(root);
        System.out.println();

        System.out.println("中序遍历");
        myBinaryTree.inOrder(root);
        System.out.println();

        System.out.println("后序遍历");
        myBinaryTree.postOrder(root);
        System.out.println();

        System.out.println("获取节点个数");
        int ret=myBinaryTree.size2(root);
        System.out.println(ret);

        System.out.println("叶子节点个数");
        int Ret=myBinaryTree.getLeafNodeCount2(root);
        System.out.println(Ret);

        System.out.println("第k层个数");
        int ret2=myBinaryTree.getKLevelNodeCount(root,2);
        System.out.println(ret2);

        System.out.println("树的深度");
        int ret3=myBinaryTree. getHeight(root);
        System.out.println(ret3);
        System.out.println("-----------");
        int ret5=myBinaryTree.getHeight(root);
        System.out.println(ret5);
    }

    public static void main14(String[] args) {
        MyStack myStack=new MyStack();
        myStack.push(20);
        myStack.push(25);
        myStack.push(10);
        myStack.push(44);
        System.out.println(myStack.pop());
        System.out.println(myStack.usedSize);
    }


    public static void main13(String[] args) {
        LinstNode linstNode =new LinstNode();
        linstNode.addfirst(12);
        linstNode.addfirst(22);
        linstNode.addfirst(33);
        linstNode.addfirst(44);
        linstNode.addfirst(55);

        int ret= linstNode.findk(3);
        System.out.println(ret);

    }

    public static void main12(String[] args) {
        LinstNode linstNode =new LinstNode();
        linstNode.addfirst(12);
        linstNode.addfirst(22);
        linstNode.addfirst(22);
        linstNode.addfirst(12);
        linstNode.dell(22);
        linstNode.display();
    }
    public static void main11(String[] args) {
        LinstNode linstNode =new LinstNode();
        linstNode.addfirst(12);
        linstNode.addfirst(22);
        linstNode.addfirst(22);
        linstNode.addfirst(12);
        int ret= linstNode.size();
        System.out.println(ret);
    }
    public static void main10(String[] args) {
        LinstNode linstNode =new LinstNode();

        linstNode.addfirst(12);
        linstNode.addfirst(22);
        linstNode.addfirst(22);
        linstNode.addfirst(12);
        int ret= linstNode.findmiddle();
        System.out.println(ret);
    }

    public static void main9(String[] args) {
        MylinstNode mylinstNode = new MylinstNode();
        mylinstNode.empty();
        mylinstNode.display();;
    }

    public static void main8(String[] args) {
        MylinstNode mylinstNode = new MylinstNode();
        mylinstNode.addlast(2);
        mylinstNode.addlast(4);
        mylinstNode.addlast(4);
        mylinstNode.addlast(5);
        mylinstNode.dellall(4);
        mylinstNode.display();
    }

    public static void main7(String[] args) {
        MylinstNode mylinstNode = new MylinstNode();
        mylinstNode.addlast(2);
        mylinstNode.addlast(3);
        mylinstNode.addlast(4);
        mylinstNode.addlast(5);
        mylinstNode.dell(4);
        mylinstNode.display();
    }
    public static void main6(String[] args) {
        MylinstNode mylinstNode = new MylinstNode();
        mylinstNode.addlast(2);
        mylinstNode.addlast(3);
        mylinstNode.addlast(4);
        mylinstNode.addlast(5);
        mylinstNode.addanywhere(0,100);
        mylinstNode.display();
    }

    public static void main5(String[] args) {
        MylinstNode mylinstNode = new MylinstNode();
        mylinstNode.addfirst(1);
        mylinstNode.addfirst(2);
        mylinstNode.addfirst(3);
        mylinstNode.addfirst(4);
        mylinstNode.display();
    }

    /**
     * 返回有环链表的第一个节点
     */
    public class Solution {
        public LinstNode.Node detectCycle(LinstNode.Node head) {
            if(head==null) return null; //是否为空链表
            LinstNode.Node slow=head;
            LinstNode.Node fast=head;
            while (fast != null && fast.next != null){
                fast=fast.next.next;
                slow=slow.next;
                if(slow==fast){  //说明链表有环
                    break;
                }
            }
            //循环结束的情况有3种
            if(fast == null || fast.next == null){
                return null;
            } //1.2种不满足
            //则链表有环
            fast=head;
            while(slow != fast){
                slow=slow.next;
                fast=fast.next;
            }
            return fast;
        }
    }

    /**
     * 判断有环（循环）链表
     */
    public static boolean isloop(LinstNode.Node head){
        LinstNode.Node fast=head;
        LinstNode.Node slow=head;
        while (fast != null && fast.next != null){
            fast=fast.next.next;
            slow=slow.next;
            if (fast==slow){
                return true;
            }
        }
        return false;
    }

    public static void main4(String[] args) {

        LinstNode linstNode =new LinstNode();
        linstNode.creatlist();
        boolean ret=isloop(linstNode.head);
        System.out.println(ret);
    }

    /**
     * 判断回文
     * @param head
     * @return
     */
    public  static  boolean judge( LinstNode.Node head){
        if (head==null || head.next==null)  return true; //只有一个节点，必定回文
        LinstNode.Node slow=head;
        LinstNode.Node fast=head;
        while (fast != null && fast.next != null){   //1.先找中间点
            fast=fast.next.next;
            slow=slow.next;
        }

        LinstNode.Node cur = slow.next;  //2.翻转
        while (cur != null){
            LinstNode.Node curNext=cur.next;
            cur.next=slow;
            slow=cur;
            cur=curNext;
        }

        while ( slow != head ){   //判断回文
            if (head.val != slow.val){
                return false;
            }
            head=head.next;
            slow=slow.next;
            if (head.next == slow ){
                return true;
            }
        }
        return true;
    }

    public static void main3(String[] args) {
        LinstNode linstNode =new LinstNode();
        linstNode.addfirst(12);
        linstNode.addfirst(22);
        linstNode.addfirst(32);
        linstNode.addfirst(22);
        linstNode.addfirst(12);
        //test2.display();
        boolean ret=judge(linstNode.head);
        System.out.println(ret);
    }
    /**
     * 合并两个链表
     * @param head1 第一个链表的头
     * @param head2
     * @return
     */
    public static  LinstNode.Node mergeTwo(LinstNode.Node head1, LinstNode.Node head2){
        LinstNode.Node newhead=new LinstNode.Node(-1);//定义一个傀儡头节点
        LinstNode.Node tmp=newhead;  //定义一个变量指向傀儡头节点

        while (head1 != null && head2 != null){
            if (head1.val<=head2.val){
                tmp.next=head1;
                head1=head1.next;
                tmp=tmp.next;
            }else {
                tmp.next=head2;
                head2=head2.next;
                tmp=tmp.next;
            }
        }
        //此时head1或者head2必定至少有一个为null
        if (head1!=null){
            tmp.next=head1;
        }else {
            tmp.next=head2;
        }
        return newhead;
    }
    public static void main2(String[] args) {
        LinstNode linstNode =new LinstNode();
        linstNode.addfirst(12);
        linstNode.addfirst(22);
        linstNode.addfirst(32);
        linstNode.addfirst(42);
        linstNode.display();

        System.out.println();
        LinstNode test1=new LinstNode();
        test1.addfirst(15);
        test1.addfirst(23);
        test1.addfirst(30);
        test1.addfirst(44);
        test1.display();
        System.out.println();

        LinstNode.Node ret=mergeTwo(linstNode.head, test1.head);
        test1.display();
    }


    public static void main1(String[] args) {
   LinstNode linstNode =new LinstNode();
   linstNode.creatlist();
   linstNode.display();
        System.out.println(linstNode.find(23));
        System.out.println("头插入之后：");
    //test2.addfirst(233);
    //test2.display();
        System.out.println("========");
        System.out.println("尾插之后：");
    linstNode.addend(30);
    linstNode.display();
        System.out.println("-----------");
        System.out.println("删除节点后：");
        linstNode.delete(23);
        linstNode.display();
        System.out.println("任意插入后：");
        linstNode.add(1000,3);
        linstNode.display();
        System.out.println("=============");
        linstNode.dell(1000);
        linstNode.display();
        //System.out.println("============删除所有key节点=======");
        //test2.dellAll(12);
        //test2.display();
        //System.out.println("--------全部清空-------");
        //test2.free();
        //test2.display();
        System.out.println();
        linstNode.Transpose();
        linstNode.display();

        System.out.println("寻找倒数第k个节点");

    }
}


